const express = require("express");
const router = express.Router();
const multer = require("multer");
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, "public/uploads/");
  },
  filename: function (req, file, cb) {
    const decodedName = Buffer.from(file.originalname, "latin1").toString(
      "utf8"
    );
    const fileName =
      decodedName.split(".")[0] +
      "_" +
      Date.now() +
      "." +
      decodedName.split(".")[1];
    cb(null, fileName);
  },
});
const upload = multer({ storage });

const UserController = require("../../controllers/admin/UserController");
// 登陆
router.post("/login", UserController.login);
// 上传图片
router.post("/uploadPic", upload.single("file"), UserController.upload);
// 注册
router.post("/regis", UserController.addUser);
// 获取个人信息
router.get("/getInfo", UserController.getInfo);
// 修改个人信息
router.post("/edit", upload.single("file"), UserController.edit);
// 删除当前角色
router.delete("/delete", UserController.delete);
// 获取所有用户
router.get("/getAllUser", UserController.getAllUser);
module.exports = router;
